﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class report : Basic
{
    public string str01 = "";
    public string str02 = "";
    public string str03 = "";  //左上手编
    public string str04 = "";  //近期市场焦点
    public string strJHWJ = "";
    public string strYJYC = "";
    public string strSCJD = "";
    public Nav nav = new Nav();
    protected void Page_Load(object sender, EventArgs e)
    {
        str04 = Pub.strSCJD();

        str03 = sb03().ToString();

        strSCJD = sb焦点().ToString();

        strYJYC = sb业绩预测().ToString();

        str01 = sbList("0301", 6).ToString() + sbList("0302", 6).ToString();

        str02 = sbList2("0803", 5).ToString() + sbList2("0802", 5).ToString() + sbList2("0804", 5).ToString() + sbList2("0805", 5).ToString();

        strJHWJ = sb机会挖掘().ToString();
    }



    protected StringBuilder sb焦点()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/scjd.ashx";
            string str = Pub.LoadData(url);
            Topics obj = JsonConvert.DeserializeObject<Topics>(str);

            if (obj != null)
            {
                sb.AppendLine("<div class=\"report_r_1_3\">");
                sb.AppendLine("<div class=\"report_r_1_1\"><a href=\"" + obj.News.Url + "\" ><img src=\"" + obj.News.ImgUrl + "\" width=\"180\" height=\"130\" /></a></div>");
                sb.AppendLine("<div class=\"report_r_1_2\">");
                sb.AppendLine("<ul>");
                sb.AppendLine("<li class=\"h2 center\"><a href=\""+obj.News.Url+"\" class=\"b\">" + obj.News.Title + "</a></li>");
                sb.AppendLine("<li class=\"center\">影响力：" + sbXX(obj.News.YXL) + "　关注度：" + sbXX(obj.News.GZD) + "</li>");
                sb.AppendLine("<li>" + OTO.CutStr(obj.News.Content,120) + " <a href=\"" + obj.News.Url + "\" class=\"b\">[详细]</a></li>");
                sb.AppendLine("</ul>");
                sb.AppendLine("</div>");
                sb.AppendLine("<div class=\"clearok\"></div>");
                sb.AppendLine("</div>");
                //涉及股票
                sb.AppendLine("<div class=\"report_bg report_r_1 font-weight\">涉及股票</div>");
                sb.AppendLine("<div class=\"report_r_sjgp\" id=\"sjgp\">");
                sb.AppendLine("<ul class=\"report_xx\">");
                sb.AppendLine("<li class=\"report_r_sjgp_1\">研报</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_3\">股票名称</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_2\">最新价</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_2\">涨跌幅</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_3\">所属行业</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_3\">体检评分</li>");
                sb.AppendLine("<li class=\"report_r_sjgp_4\">千股千评</li>");
                sb.AppendLine("</ul>");
                sb.AppendLine("<div style=\"display:none;\"></div>");
                foreach (var m in obj.Stocks)
                {
                    sb.AppendLine("<ul sjgp=\"true\">");
                    sb.AppendLine("<li class=\"report_r_sjgp_1\" style=\"text-align:left;\"><img src=\"http://down3.emstock.com.cn/www/images/report_ico2.jpg\" /></li>");
                    sb.AppendFormat("<li class=\"report_r_sjgp_3\"><a href=\"{2}gg{1}.shtml\" class=\"b\">{0}</a></li>",m.StockName,m.Stock,quoteUrl);
                    sb.AppendLine("<li class=\"report_r_sjgp_2 \"><span zxj=\"zxj2\" code2=\"" + m.Stock + "\" class=\"red\">-</span></li>");
                    sb.AppendLine("<li class=\"report_r_sjgp_2\"><span zdf=\"zdf2\" class=\"red\">-</span></li>");
                    sb.AppendLine("<li class=\"report_r_sjgp_3\">" + m.HYMC + "</li>");
                    sb.AppendLine("<li class=\"report_r_sjgp_3 red\">" + OTO.ToDecLine(m.TJPF,0,"-") + "分</li>");
                    sb.AppendLine("<li class=\"report_r_sjgp_4\">" + m.QGQP + "</li>");
                    sb.AppendLine("</ul>");
                    int len = m.YBLst.Count;
                    if (len > 4)
                        len = 4;
                    sb.AppendLine("<div class=\"report_r_sjgp_m report_bg\"  sjgpd=\"true\" style=\"display:none;\">");
                    sb.AppendLine("<ul>");
                    for (int i = 0; i < len; i++)
                    {
                        sb.AppendFormat(" <li>·<a href=\"{1}\" class=\"b\">{0}</a></li>", m.YBLst[i].Tile,GetNewsUrl("04", "0305", m.YBLst[i].id));
                    }
                    //sb.AppendLine(" <li style=\"text-align:right;\"><a href=\"#\" class=\"b\">更多中路股份研报>></a></li>");
                    sb.AppendLine("</ul>");
                    sb.AppendLine("</div>");
                }
                sb.AppendLine("</div>");
            }
        }
        catch { }
        return sb;
    }


    protected StringBuilder sbXX(int n)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            for (int i = 0; i < n; i++)
            {
                sb.Append("<img src=\"http://down3.emstock.com.cn/www/images/report_ico1.png\" />");
            }
        }
        catch { }
        return sb;
    }


    protected StringBuilder sbList(string CID, int len)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsList.ashx?typeid=" + CID + "";
            string str = Pub.LoadData(url);
            NewsList obj = JsonConvert.DeserializeObject<NewsList>(str);

            if (obj != null)
            {
                sb.AppendLine("<li><div class=\"report_l_1_1 h3 red\" style=\" margin-top:10px;\">" + obj.typename + "<span class=\"report_more\"><a href=\"" + GetNewListUrl("04", CID, 1) + "\" class=\"b\">更多>></a></span></div></li>");
                int i = 0;
                foreach (var item in obj.list)
                {
                    i++;
                    sb.AppendLine("<li> ·<a href=\"" + GetNewsUrl("04", CID, item.Id) + "\">" + item.Title + "</a> </li>");
                    if (i >= len)
                        break;
                }
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sbList2(string CID, int len)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl+ "news/NewsList.ashx?typeid=" + CID + "";
            string str = Pub.LoadData(url);
            NewsList obj = JsonConvert.DeserializeObject<NewsList>(str);

            if (obj != null)
            {
                sb.AppendLine("<div class=\"report_h h3 red\">" + obj.typename + "<span class=\"report_more\"><a href=\"" + GetNewListUrl("04",CID,1) + "\" class=\"b\">更多>></a></span></div>");
                sb.AppendLine(" <div class=\"report_content_padd\">");
                sb.AppendLine("<ul>");
                int i = 0;
                foreach (var item in obj.list)
                {
                    i++;
                    sb.AppendLine("<li> ·<a href=\"" +GetNewsUrl("04", CID, item.Id)  + "\">" + item.Title + "</a> </li>");
                    if (i >= len)
                        break;
                }
                sb.AppendLine("</ul>");
                sb.AppendLine("</div>");
            }
        }
        catch { }
        return sb;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    protected StringBuilder sb机会挖掘()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "stock/StockPool_summary.ashx?top=6";
            string str = Pub.LoadData(url);
            JHWJ obj = JsonConvert.DeserializeObject<JHWJ>(str);

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">");
            sb.AppendLine("  <tr>");
            sb.AppendLine("    <td><div class=\"report_h font-weight\">机构股票池<span class=\"report_more\"><a href=\"report_jggpc.shtml\" class=\"b\">更多>></a></span></div>");
            sb.AppendLine("      <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">");
            sb.AppendLine("        <tr align=\"center\">");
            sb.AppendLine("          <td>证券简称</td>");
            sb.AppendLine("          <td>研究机构</td>");
            sb.AppendLine("          <td>报告摘要</td>");
            sb.AppendLine("        </tr>");
            int i = 0;
            foreach (var item in obj.机构股票池.list)
            {
                i++;
                string _class = "class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendLine("<tr " + _class + ">");
                sb.AppendFormat("<td align=\"center\"><a href=\"{0}gg{1}.shtml\" class=\"b\">{2}</a></td>", quoteUrl, item.StockId, item.StockName);
                sb.AppendFormat("<td align=\"center\">{0}</td>",item.OName);
                sb.AppendFormat("<td align=\"center\"><a href=\"reportContent_{0}.shtml\" class=\"b\">摘要</a></td>", item.id);
               sb.AppendLine("</tr>");
            }
            sb.AppendLine("      </table></td>");
            sb.AppendLine("    <td><div class=\"report_h font-weight\">投资评估调高<span class=\"report_more\"><a href=\"report_tzpj.shtml\" class=\"b\">更多&gt;&gt;</a></span></div>");
            sb.AppendLine("        <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">");
            sb.AppendLine("          <tr>");
            sb.AppendLine("            <td align=\"center\">证券简称</td>");
            sb.AppendLine("            <td align=\"center\">最新评级</td>");
            sb.AppendLine("            <td align=\"center\">上次评级</td>");
            sb.AppendLine("            <td align=\"center\">报告摘要</td>");
            sb.AppendLine("          </tr>");
            i = 0;
            foreach (var item in obj.投资评估调高.list)
            {
                i++;
                string _class = "class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendLine("<tr " + _class + ">");
                sb.AppendFormat("<td align=\"center\"><a href=\"{0}gg{1}.shtml\" class=\"b\">{2}</a></td>", quoteUrl, item.StockId, item.StockName);
                sb.AppendLine("<td align=\"center\">" + item.InvestmentGrade + "</td>");
                sb.AppendLine("<td align=\"center\">" + item.SCPJ + "</td>");
                sb.AppendFormat("<td align=\"center\"><a href=\"reportContent_{0}.shtml\" class=\"b\">摘要</a></td>", item.id);
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("        </table></td>");
            sb.AppendLine("  </tr>");
            sb.AppendLine("  <tr>");
            sb.AppendLine("    <td><div class=\"report_h font-weight\">机构首次关注股票<span class=\"report_more\"><a href=\"report_jggz.shtml\" class=\"b\">更多&gt;&gt;</a></span></div>");
            sb.AppendLine("        <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">");
            sb.AppendLine("          <tr>");
            sb.AppendLine("            <td align=\"center\">证券简称</td>");
            sb.AppendLine("            <td align=\"center\">最新评级</td>");
            sb.AppendLine("            <td align=\"center\">报告摘要</td>");
            sb.AppendLine("          </tr>");
            i = 0;
            foreach (var item in obj.机构首次关注股票.list)
            {
                i++;
                string _class = "class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendLine("<tr " + _class + ">");
                sb.AppendFormat("<td align=\"center\"><a href=\"{0}gg{1}.shtml\" class=\"b\">{2}</a></td>", quoteUrl, item.StockId, item.StockName);
                sb.AppendLine("<td align=\"center\">" + item.InvestmentGrade + "</td>");
                sb.AppendFormat("<td align=\"center\"><a href=\"reportContent_{0}.shtml\" class=\"b\">摘要</a></td>", item.id);
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("        </table></td>");
            sb.AppendLine("    <td valign=\"top\"><div class=\"report_h font-weight\">机构关注度最高<span class=\"report_more\"><a href=\"report_ylyc.shtml\" class=\"b\">更多&gt;&gt;</a></span></div>");
            sb.AppendLine("        <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">");
            sb.AppendLine("          <tr>");
            sb.AppendLine("            <td align=\"center\">证券简称</td>");
            sb.AppendLine("            <td align=\"center\">最新评级</td>");
            sb.AppendLine("            <td align=\"center\">研究机构</td>");
            sb.AppendLine("            <td align=\"center\">报告摘要</td>");
            sb.AppendLine("          </tr>");
            i = 0;
            foreach (var item in obj.机构关注度最高.list)
            {
                i++;
                string _class = "class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendLine("<tr align=\"center\" " + _class + ">");
                sb.AppendLine("<tr " + _class + ">");
                sb.AppendFormat("<td align=\"center\"><a href=\"{0}gg{1}.shtml\" class=\"b\">{2}</a></td>", quoteUrl, item.StockId, item.StockName);
                sb.AppendLine("<td align=\"center\">" + item.InvestmentGrade + "</td>");
                sb.AppendLine("<td align=\"center\">" + item.OName + "</td>");
                sb.AppendFormat("<td align=\"center\"><a href=\"reportContent_{0}.shtml\" class=\"b\">摘要</a></td>", item.id);
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("        </table></td>");
            sb.AppendLine("  </tr>");
            sb.AppendLine("</table>");
        }
        catch { }
        return sb;
    }


    protected StringBuilder sb业绩预测()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "stock/StockPool_GetOne.ashx?flag=yjyc&skip=0&top=13";
            string str = Pub.LoadData(url);
            NewStock_BData_C obj = JsonConvert.DeserializeObject<NewStock_BData_C>(str);


            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("<tr align=\"center\" class=\"tableLargeHead\">");
            sb.AppendLine("<td>证券名称</td>");
            sb.AppendLine("<td>机构</td>");
            sb.AppendLine("<td>最新价格</td>");
            sb.AppendLine("<td>目标价</td>");
            sb.AppendLine("<td>目标涨幅</td>");
            sb.AppendLine("<td>评级</td>");
            sb.AppendLine("<td>10每股收益</td>");
            sb.AppendLine("<td>11每股收益</td>");
            sb.AppendLine("<td>报告摘要</td>");
            sb.AppendLine("</tr>");
            foreach (var m in obj.list)
            {
                sb.AppendLine("<tr align=\"center\" onmouseover=\"this.className='tr_over'\" onmouseout=\"this.className='tr_out'\">");
                sb.AppendFormat("<td><a href=\"{0}gg{1}.shtml\" class=\"b\">{2}</a></td>", quoteUrl, m.StockId, OTO.ToStr(m.StockName, "&nbsp;"));
                sb.AppendLine("<td>" + OTO.ToStr(m.OName, "&nbsp;") + "</td>");
                sb.AppendLine("<td><span zxj=\"zxj\" code=\"" + m.StockId + "\" class=\"red\">-</span></td>");
                sb.AppendLine("<td>" + OTO.ToDecimal(m.TargetPrice, 0).ToString("f2") + "</td>");
                sb.AppendLine("<td><span zdf=\"zdf\" zdfv=\"" + m.TargetPrice + "\">-</span></td>");
                sb.AppendLine("<td>" + m.InvestmentGrade + "</td>");
                sb.AppendLine("<td>" + OTO.ToDecimal(m.PerIncome1, 0).ToString("f2") + "</td>");
                sb.AppendLine("<td>" + OTO.ToDecimal(m.PerIncome2, 0).ToString("f2") + "</td>");
                sb.AppendFormat("<td><a href=\"reportContent_{0}.shtml\" class=\"b\">摘要</a></td>", m.id);
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</table>");
        }
        catch { }
        return sb;
    }


    protected StringBuilder sb03()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/Headline.ashx?id=cbjx";
            string str = Pub.LoadData(url);
            NewsHeadEnty obj2 = JsonConvert.DeserializeObject<NewsHeadEnty>(str);
            if (obj2 != null)
            {
                sb.AppendFormat("<li class=\"h2 center blue\"><a href=\"{1}\" class=\"b\">{0}</a></li>", obj2.Title, obj2.Url);
                sb.AppendFormat("<li class=\"font12 gray\">{0}<a href=\"{1}\" class=\"r\">[详细]</a></li>", obj2.Content, obj2.Url);
            }

            sb.AppendLine("<li class=\"line\" style=\"clear:both;\">&nbsp;&nbsp;</li>");
            str = Pub.LoadData(jsonUrl + "comm/module.ashx?id=scyj_1");
            List<List<NewsSBEnty>> obj = JsonConvert.DeserializeObject<List<List<NewsSBEnty>>>(str);
            foreach (var m in obj)
            {
                if (m.Count == 2)
                {
                    sb.AppendFormat("<li class=\"font12\"><span class=\"red\">{0}：</span><a href=\"{1}\">{2}</a> </li>", m[0].Text, m[1].Url, m[1].Text);
                }
            }
        }
        catch { }
        return sb;
    }
}